﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace TDUpdate
{
    class LevelLoader
    {
        static public TileEnum[,] loadTextFile(string levelName)
        {
            string filename = @"Levels\" + levelName + ".txt";

            string[] lines = File.ReadAllLines(filename);

            int maxColumn = 0;

            foreach (string line in lines)
	        {
		        if(maxColumn < line.Count())
                    maxColumn = line.Count();
	        }

            TileEnum[,] fields = new TileEnum[maxColumn, lines.Count()-1];

            for (int row = 0; row < lines.Length-1; row++)
            {
                for (int column = 0; column < lines[row].Length; column++)
                {
                    switch (lines[row][column])
                    {
                        case '.': fields[row,column] = TileEnum.Lawn; break;
                        case '#': fields[row,column] = TileEnum.Lane; break;
                        case '~': fields[row,column] = TileEnum.Water; break;
                    }
                }
            }
            return fields;
        }
    }
}
